//
//  LinkSellerViewController.m
//  HongFuShop
//
//  Created by chirui on 2017/8/3.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "LinkSellerViewController.h"

@interface LinkSellerViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * _tableView;
    NSDictionary * dataDic;

}

@end

@implementation LinkSellerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor =[UIColor whiteColor];
    TitleView(@"联系卖家");
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_public_return" target:self action:@selector(back)];
    [self creatTableView];
    
    [self getShoperMessageRequest];
}

-(void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)creatTableView {
    
    _tableView  =[[UITableView alloc]initWithFrame:CGRectMake(0,0, WIDTH, HEIGHT)
                                             style:UITableViewStyleGrouped];
    _tableView.dataSource=self;
    _tableView.delegate =self;
    UIView * view =[[UIView alloc]init];
    _tableView.tableFooterView =view;
    [self.view addSubview:_tableView];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 3;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 60;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString * cellId =@"cellid";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell==nil) {
        
        cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
    }else {
        
        while ([cell.contentView.subviews lastObject]) {
            
            [[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSArray * imageArray = @[@"icon_tel_shop",@"icon_tel_address",@"icon_tel_tel"];
    NSArray * titleArray = @[@"上级经销商",@"经销商地址",@"联系电话"];
    
    cell.imageView.image = ImageName(imageArray[indexPath.row]);
    
    cell.textLabel.text = titleArray[indexPath.row];
    cell.textLabel.textColor = RGB(0x666666);
    cell.textLabel.font =[UIFont systemFontOfSize:15];
    
    switch (indexPath.row) {
        case 0:
            cell.detailTextLabel.text = dataDic[@"user_name"];
            break;
        case 1:
            cell.detailTextLabel.text = [NSString stringWithFormat:@"%@%@",dataDic[@"area"],dataDic[@"addr"]];
            break;
        case 2:
            cell.detailTextLabel.text = dataDic[@"phone"];
            break;

            
        default:
            break;
    }
    cell.detailTextLabel.textColor = [UIColor blackColor];
    cell.detailTextLabel.font =[UIFont systemFontOfSize:15];
    return cell;

}

-(void)getShoperMessageRequest{
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",NetWorkAddress_api,get_sellerMessage_api];
    NSDictionary * dic = @{@"user_id":USER_DEFAULTGet(@"user_id"),
                           @"token":USER_DEFAULTGet(@"token")};
        SHuiMBhubNoTimeLoding;
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
            
        dataDic = responseObject[@"datas"];
            
        } else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
        [_tableView reloadData];
        
    } failed:^(NSError *error) {
        SHuiMBHidleYes;
        SHuiMBhudTextNetError;
        
    }];
    
}

@end
